﻿using MediatR;
using ProduceBasicData.Api.Application.Command.WarehouseManage;
using ProduceBasicData.Domain.WarehouseManage;
using ProduceBasicData.ErrorCode;
using ProduceBasicData.Infrastructure.Interface;

namespace ProduceBasicData.Api.Application.Handler.WarehouseManage
{
    /// <summary>
    /// 仓库下拉框命令处理器
    /// </summary>
    public class GetWarehouseDropdownCommandHandler : IRequestHandler<GetWarehouseDropdownCommand, ApiResult<List<Warehouse>>>
    {
        private readonly IBaseRespository<Warehouse> _warehouse;

        public GetWarehouseDropdownCommandHandler(IBaseRespository<Warehouse> warehouse)
        {
            _warehouse = warehouse;
        }

        public Task<ApiResult<List<Warehouse>>> Handle(GetWarehouseDropdownCommand request, CancellationToken cancellationToken)
        {
            var result = new ApiResult<List<Warehouse>>()
            {
                Code = ApiEnum.Success,
                Msg = "仓库查询成功"
            };
            var listhouse = _warehouse.GetAll();

            result.Data = listhouse.ToList();

            return Task.FromResult(result);
        }
    }
}